% !TEX root = EUDAQUserManual.tex
\section{Support User Defined Event Type}\label{sec:NewDataHandling}
In the EUDAQ framework, the definition \texttt{data} usually means an object of eudaq::Event or its derivations. 

\subsection{Event}
eudaq::Event is serializable as it is derived from eudaq::Serializable and implements
\begin{listing}
  Event(Deserializer &);
  virtual void Serialize(Serializer &) const;    
\end{listing}

There are three eudaq::Event derivations in the default installation of EUDAQ. They are \lstinline[style=cpp]{RawDataEvent} (\autoref{sec:convrawdata}), \lstinline[style=cpp]{StandardEvent} (\autoref{sec:convstddata}) and \lstinline[style=cpp]{LCEvent}. The eudaq::Event derivations are serializable. But if there are additional member variables introduced to derived Events, the new variable should be serialized along with the other variables defined in eudaq::Event. If this is not done, the unserialized data will be lost.

It is recommend to reuse the raw data blocks \lstinline[style=cpp]{m_blocks} of eudaq::Event. Then the base eudaq::Event will serialize and deserialize the \lstinline[style=cpp]{m_blocks}.\\

\subsection{FileWriter}\label{sec:FileWriterWriting}
Usually, the objects of eudaq::Event and its derivations are the only data going to be stored in disk for later offline analysis. The user may prefer to write Event data in other format which is human readable or widely used by other software. In order to define a new file format, the user can define a class derived from eudaq::FileWriter.


\subsubsection{FileWriter Prototype}
\lstinputlisting[label=ls:filewritedec, style=cpp, linerange=BEG*DEC-END*DEC]{../../main/lib/core/include/eudaq/FileWriter.hh}

\subsubsection{Example Code: NativeFileWriter}
No matter if the user defined Event reuses the \lstinline[style=cpp]{m_blocks} raw data block or does serialization of new variables itself, it can write to disk in binary format (aka native) which can only be read by EUDAQ.

\lstinputlisting[label=ls:rawfilewritecc, style=cpp]{../../main/lib/core/src/NativeFileWriter.cc}

\subsection{FileReader}\label{sec:FileReaderWriting}
To reconstruct the Event from a disk file in native format or user-defined format, the class eudaq::FileReader is provided. Each writing data format should have its correlated implementation of FileReader to access the disk file.

\subsubsection{FileReader Prototype}
\lstinputlisting[label=ls:filereaderdec, style=cpp, linerange=BEG*DEC-END*DEC]{../../main/lib/core/include/eudaq/FileReader.hh}

\subsubsection{Example Code: NativeFileReader}
\lstinputlisting[label=ls:rawfilereadercc, style=cpp]{../../main/lib/core/src/NativeFileReader.cc}
